package org.example.dayu521.conf;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;

public class WebMvc {

    public final static class VersionHolder{
        public final static ThreadLocal<String> tl=new ThreadLocal<>();
        private VersionHolder(){}
    }

    public static String getVersion(){
        return VersionHolder.tl.get();
    }

    public static void setVersion(String s){
        VersionHolder.tl.set(s);
    }

    public final static class KTInterceptor implements HandlerInterceptor {

        @Override
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
            var h=request.getHeader("Version");
            if(h!=null&&!h.isEmpty()){
                setVersion(h);
            }
            return true;
        }
    }

}